﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.Extensions.Configuration;
using AgencyManagerSystem.Common;

namespace AgencyManagerSystem
{
    public static class InitHelper
    {
        public static void InitVariable(IConfiguration configuration)
        {
            LogHelper.Log(typeof(InitHelper).Name,"Init config...");
            Variable.SQL_HOST = configuration["ConnectionStrings:Host"];
            int port = 3306;
            Int32.TryParse(configuration["ConnectionStrings:Port"],out port);
            Variable.SQL_PORT = port;
            Variable.SQL_DBNAME = configuration["ConnectionStrings:DBname"];
            Variable.SQL_CHARSET = configuration["ConnectionStrings:CharSet"];
            Variable.SQL_USER = configuration["ConnectionStrings:User"];
            Variable.SQL_PASSWORD = configuration["ConnectionStrings:Password"];
            Variable.SECRETKEY = configuration["Access:SecretKey"];
            Variable.VALIDAUDIENCE = configuration["Access:ValidAudience"];
            Variable.VALIDISSUER = configuration["Access:ValidIssuer"];
            int expires = 3600;
            Int32.TryParse(configuration["Access:Expires"], out expires);
            Variable.EXPIRES = expires;
            //Variable.REDIS_HOST = configuration["Redis:Host"];
            //int redisPort = 6379;
            //Int32.TryParse(configuration["Redis:Port"], out redisPort);
            //Variable.REDIS_PORT = redisPort;
            //Variable.REDIS_PASSWORD = configuration["Redis:Password"];


            Variable.ERP_HOST = configuration["ERPConnection:Host"];
            int erpport = 1433;
            Int32.TryParse(configuration["ERPConnection:Port"], out erpport);
            Variable.ERP_PORT = erpport;
            Variable.ERP_DBNAME = configuration["ERPConnection:DBname"];
            Variable.ERP_USER = configuration["ERPConnection:User"];
            Variable.ERP_PASSWORD = configuration["ERPConnection:Password"];

            LogHelper.Log(typeof(InitHelper).Name, "Init config complete!");
        }
    }
}
